using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace KL.Standard.Core.Converter
{
    /// <summary>
    /// 日期格式化
    /// </summary>
    public class DayJsonConverter: DateTimeConverterBase
    {
        private static IsoDateTimeConverter dtConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy/MM/dd" };

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return dtConverter.ReadJson(reader, objectType, existingValue, serializer);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            dtConverter.WriteJson(writer, value, serializer);
        }
    }
    
    /// <summary>
    /// 日期格式化
    /// </summary>
    public class DayJsonConverter2: DateTimeConverterBase
    {
        private static IsoDateTimeConverter dtConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd" };

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return dtConverter.ReadJson(reader, objectType, existingValue, serializer);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            dtConverter.WriteJson(writer, value, serializer);
        }
    }

    /// <summary>
    /// 标注该属性 用日期的格式
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class JsonDayAttribute : System.Attribute
    {
        
    }
}